package com.myjpa.common.web;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import org.apache.commons.collections4.MapUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: yaoll
 * @date: 2020-09-04
 * @verison: 1.0
 */
public class MapResponse extends BaseResponse<Map<String, Object>> {

	public MapResponse() {
		super();
		super.setResult(SUCCESS);
	}

	@JsonAnySetter
	public void add(String name, Object value) {
		if (data == null) {
			data = new HashMap<String, Object>();
		}
		data.put(name, value);
	}

	@JsonAnyGetter
	@Override
	public Map<String, Object> getData() {
		return data;
	}

	public String getString(String key) {
		return MapUtils.getString(data, key);
	}

	public Integer getInteger(String key) {
		return MapUtils.getInteger(data, key);
	}
}
